<template>
    <div class="app-container">
        <!-- 表格 -->
        <iv-table 
            :data="tableData" 
            :columns="tableColumn" 
            v-loading="loading" 
            element-loading-text="正在查询中。。。" 
            highlight-current-row 
            stripe 
            @selection-change="handleSelectionChange" 
            />
        <!-- 分页 -->
        <iv-pagination :autoScroll="scroll" :query="listQuery" @initList="initList"/>
        <!-- 回到顶部 -->
        <back-to-top :visibility-height="300" :back-position="50" transition-name="fade"/>
    </div>
</template>
<script>
import ivPagination from '@/components/IvPagination'
import ivTable from '@/components/IvTable'
import { tableColumn } from './btnTable'
import backToTop from '@/components/BackToTop'
import { findList } from "@/api/file";

export default {
    components: {
        ivPagination,
        ivTable,
        backToTop
    },
    data(){
        return {
            tableColumn: tableColumn(),
            listQuery: {start: 0, limit: 10, total: 0, current: 1},
            form: {},
            dialog: {show: false, title: ''},
            loading: false,
            tableData: [],
            multipleSelection: [],
            scroll: false
        }
    },
    methods: {
        search(){
            this.initList();
        },
        handleSelectionChange(val){
            this.multipleSelection = val
        },
        autoScroll(){
            this.scroll = !this.scroll;
            this.$message.success('顶部回滚' + (this.scroll ? '开启' : '关闭'))
        },
        async initList(){
            this.loading = true;
            const userString = localStorage.getItem('userInfo')
            let userInfo = {}
            if (userString) userInfo = JSON.parse(userString)
            let { data } = await findList({...this.listQuery, user_name: userInfo.user_name });
            const { count, list } = data
            this.loading = false
            this.tableData = list;
            this.listQuery.total = count;
        },
    },
    created(){
        this.initList();
    }
}
</script>
